package com.school.basic.controller;

import com.school.basic.entity.ClassInfo;
import com.school.basic.service.ClassInfoService;
import com.school.untils.ResultEntity;
import com.school.untils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(tags = "班级信息管理")
@RestController
@RequestMapping("/classInfo")
public class ClassesController {
    @Autowired
    ClassInfoService classInfoService;

    // 新增
    @ApiOperation("班级信息增加")
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public ResultEntity addClassInfo(@RequestBody ClassInfo classInfo){
        return ResultUtils.build(classInfoService.addClassInfo(classInfo));
    }

    // 查询所有
    @ApiOperation("写实记录信息查询所有")
    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public ResultEntity<Object> findAll(){
        return ResultUtils.build(classInfoService.findAll());
    }

    // 更新
    @ApiOperation("班级信息更新")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public ResultEntity updateClassInfo(@RequestBody ClassInfo classInfo){
        return ResultUtils.build(classInfoService.updateClassInfo(classInfo));
    }

    // 班级人数更新
    @ApiOperation("班级人数更新")
    @RequestMapping(value = "/updateTotal",method = RequestMethod.POST)
    public void updateTotal(String id, String total){
        classInfoService.updateTotal(id,total);
    }

    // 根据id查看详情
    @ApiOperation("班级信息查看详情")
    @GetMapping("/getDetailsById/{id}")
    public ResultEntity getDetailsById(@PathVariable("id") String id){
        return ResultUtils.build(classInfoService.getDetailsById(id));
    }

    // 根据id删除
    @ApiOperation("班级信息信息删除")
    @DeleteMapping("/delete/{id}")
    public void deleteClassInfo(@PathVariable("id") String id){
        classInfoService.deleteClassInfo(id);
    }

    // 根据id批量删除
    @ApiOperation("班级信息批量删除")
    @DeleteMapping("/batch")
    public void deleteClassInfoList(String idList){
        classInfoService.deleteClassInfoList(idList);
    }

    // 根据条件分页查询
    @ApiOperation("根据条件分页查询")
    @GetMapping("/specificPage")
    public ResultEntity specificPageQueryClassInfoList(ClassInfo classInfo, @RequestParam int page, @RequestParam int size){
        return ResultUtils.build(classInfoService.specificPageQueryClassInfoList(classInfo,page,size));
    }

    // 根据学校ID查询所有
    // 根据学校ID查询所有
    @ApiOperation("根据学校ID查询所有")
    @GetMapping("/findAllBySchoolId")
    public ResultEntity<Object> findAllBySchoolId(Integer schoolId){
        return ResultUtils.build(classInfoService.findAllBySchoolId(schoolId));
    }
}
